function port = SK6_Open( COM_PORT );
% SHAKE SK6 Matlab Driver v0.00, (c) 2010 SAMH Engineering Services
%
% function port = SK6_Open( COM_PORT );
% Open a serial port connection to the SK6 and set the SK6 to the
% default configuration settings. Returns a file handle to the serial port.

% create a serial port object
global port

port = serial( COM_PORT ,'BaudRate', 460800 );

% retrieve the size that the input buffer should be set to from the configuration structure
sk6config = SK6_Config();
Hardware_Input_Buff_Size = cell2mat( sk6config ( 2 , 2 ));

% set the hardware parameters of the serial port
set( port, 'FlowControl' , 'Hardware' , 'InputBufferSize' , Hardware_Input_Buff_Size );
port.ReadAsyncMode = 'continuous';

% setup the timer callback function - that will be responsible for parsing the received data
port.TimerFcn = {'SK6_Recieve_Data_Parse_Callback'};
% retrieve the receive parse period in units of seconds
parse_period = cell2mat( sk6config ( 1 , 2 ));
port.TimerPeriod = parse_period;

% open the serial port
fopen( port );

% set the SK6 to the factory default
SK6_Write( '0113' , 'BB' );

% set all packets (includeing the ACK packets) to raw format
SK6_Write( '0002' , '16' );

% wait a few miliseconds for the SK6 to update ( and ODRs to settle )
pause( 0.1 );
end

